package com.quartz.controller;

import com.quartz.entity.QuartzObj;
import com.quartz.quartz.QuartzUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * User: lixiao
 * Created Date: 2020/8/3 11:08
 */
@RestController
@RequestMapping("/qartz")
public class quartzController {

    @Autowired
    QuartzUtil quartzUtil;

    @GetMapping(value = "/add")
    public String addQuartz(){
        QuartzObj quartzObj=new QuartzObj();
        quartzObj.setClassName("com.quartz.quartz.jobs.testJob");
        quartzObj.setPackageName("com.quartz.quartz.jobs");
        quartzObj.setCronExp("*/10 * * * * ?");
        try {
            quartzUtil.add(quartzObj);
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
            return "false";
        }
    }

    @GetMapping(value = "/beginAddAaccount")
    public String beginAddAaccount(){
        QuartzObj quartzObj=new QuartzObj();
        quartzObj.setClassName("com.quartz.quartz.jobs.JobInsertAccount");
        quartzObj.setPackageName("com.quartz.quartz.jobs");
        quartzObj.setCronExp("*/1 * * * * ?");
        try {
            quartzUtil.add(quartzObj);
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
            return "false";
        }
    }
}